﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <title>活动报名</title>
    <style type="text/css">
        .ui-tab-content {
            margin-top: 0px;
        }

        .ui-border {
            padding: 10px;
        }

        .ui-list > li {
            margin: 3px;
        }

        .ui-border {
            background-color: #fff;
        }

            .ui-border .v {
                border-top: solid 1px #ede8e8;
                padding: 5px;
                margin-top: 10px;
                font-size: 12px;
            }

                .ui-border .v span {
                    font-size: 10px;
                    float: right;
                }

        .ui-label-s {
            margin-right: 5px;
        }

        .ms-controller, [ms-controller] {
            display: none;
        }

        .pullDown, .pullUp {
            background: #fff;
            height: 40px;
            line-height: 40px;
            padding: 5px 10px;
            border-bottom: 1px solid #ccc;
            font-weight: bold;
            font-size: 14px;
            color: #888;
        }

        .pullDownIcon, #pullUp .pullUpIcon {
            display: block;
            float: left;
            width: 40px;
            height: 40px;
            background: url(../Images/pull-icon@2x.png) 0 0 no-repeat;
            -webkit-background-size: 40px 80px;
            background-size: 40px 80px;
            -webkit-transition-property: -webkit-transform;
            -webkit-transition-duration: 250ms;
        }

        .pullDownIcon {
            -webkit-transform: rotate(0deg) translateZ(0);
        }

        .pullUpIcon {
            -webkit-transform: rotate(-180deg) translateZ(0);
        }

        .flip .pullDownIcon {
            -webkit-transform: rotate(-180deg) translateZ(0);
        }

        .flip .pullUpIcon {
            -webkit-transform: rotate(0deg) translateZ(0);
        }

        .loading .pullDownIcon {
            background-position: 0 100%;
            -webkit-transform: rotate(0deg) translateZ(0);
            -webkit-transition-duration: 0ms;
            -webkit-animation-name: loading;
            -webkit-animation-duration: 2s;
            -webkit-animation-iteration-count: infinite;
            -webkit-animation-timing-function: linear;
        }

        @-webkit-keyframes loading {
            from {
                -webkit-transform: rotate(0deg) translateZ(0);
            }

            to {
                -webkit-transform: rotate(360deg) translateZ(0);
            }
        }

        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body>
    <header class="ui-header ui-header-stable ui-border-b">
        <i class="ui-icon-return" onclick="back()"></i>
        <h1>报名信息查看</h1>
    </header>
    <section class="ui-container">
        <ul class="ui-tab-content">
            <li>
                <ul class="ui-list ui-list-pure" style="background-color:#f6f0f0;" ms-controller="hdlist">
                    <li class="ui-border ui-label-list" ms-repeat-el="ctData">
                        
                        <a class="ui-list-info" href="javascript:void(0);">
                            <p>
                                <span class="ui-txt-info" style="padding-right:10px">
                                    {{el.BMLxr}}
                                </span>
                                <span class="ui-txt-info" style="padding-right:10px">
                                    {{el.BMLxDH}}
                                </span>
                                <span class="ui-badge">{{el.BMCount}}</span>
                                <span class="ui-txt-info">
                                    人
                                </span>
                            </p>
                            <p>
                                <span class="ui-txt-info">
                                    {{el.CRDate|date("yyyy-MM-dd HH:mm:ss")}}
                                </span>
                            </p>
                        </a>
                        {{issc(el.CRUser,hdtime)|html }}
                    </li>
                </ul>
                <!--<div id="hdpullDown" class="pullDown loading">
                    <span class="pullDownIcon"></span><span class="pullDownLabel">数据加载中...</span>
                </div>-->
            </li>
        </ul>
    </section>
        <script>
            document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
                //隐藏右上角按钮
                WeixinJSBridge.call('hideOptionMenu');
            });

            var strId = MobileCom.getQueryString("ID");

            //window.localStorage.removeItem("page1");
            //window.localStorage.setItem("page1", 1);

            //window.localStorage.removeItem("isjz");
            //window.localStorage.setItem("isjz", 0);

            //if (MobileCom.getCookie("szhlcode") == null) {
            //    MobileCom.setCookie("szhlcode", "8009594d-438c-42a9-a3ed-a003907d561d", 7);
            //}

            var model = avalon.define({
                $id: "hdlist",
                ctData: [],
                bmData: { "HDID": strId, "BMLxr": "", "BMLxDH": "", "BMCount": "" },
                nowuser: "",
                hdtime:"",
                sc: function (el) {
                    var tc = layer.open({
                        content: '确定要删除此报名吗？',
                        btn: ['确定', '取消'],
                        shadeClose: false,
                        yes: function () {
                            layer.close(tc);
                            var lg = $.loading({
                                content: '删除中...',
                            })
                            $.getJSON('/API/WXAPI.ashx?Action=DELHDBMITEMMODEL', { P1: el.ID }, function (resultData) {
                                lg.hide();
                                if (resultData.ErrorMsg == "") {
                                    model.ctData.remove(el);
                                    var ts = $.tips({
                                        content: "删除成功",
                                        stayTime: 2000,
                                        type: "success"
                                    })
                                    ts.on("tips:hide", function () {
                                        //window.location.reload();
                                    })
                                }
                                else {
                                    $.tips({
                                        content: "删除失败，原因：" + resultData.ErrorMsg,
                                        stayTime: 2000,
                                        type: "warn"
                                    })
                                }
                            })
                        }, no: function () {
                        }
                    })
                },
                bj: function (scel) {
                    var lg = $.loading({
                        content: '加载中...',
                    })
                    $.getJSON('/API/WXAPI.ashx?Action=GETHDBMITEMBYUSER&r=' + Math.random(), { P1: strId }, function (resultData) {
                        lg.hide();
                        if (resultData.ErrorMsg == "") {
                            var data = resultData.Result;
                            model.bmData = data;

                            var tc = layer.open({
                                type: 1,
                                //content:$("#bmxx").html(),
                                title: "报名信息",
                                content: '<div class="ui-form ui-border-t" ><div class="ui-form-item ui-border-b"><label>联系人姓名</label><input type="text" placeholder="请输入联系人姓名" id="lxr" value="' + model.bmData.BMLxr + '" /></div><div class="ui-form-item ui-border-b"><label>联系人手机</label><input type="tel" placeholder="请输入联系人手机" id="lxrsj" value="' + model.bmData.BMLxDH + '" /></div><div class="ui-form-item ui-border-b"><label>报名人数</label><input type="tel" placeholder="请输入报名人数" id="bmrs" value="' + model.bmData.BMCount + '" /></div></div>',
                                btn: ['确认', '取消'],
                                shadeClose: false,
                                yes: function () {

                                    if ($("#lxr").val() == "") {
                                        //$.tips({
                                        //    content: "请输入联系人姓名",
                                        //    stayTime: 2000,
                                        //    type: "warn"
                                        //})
                                        alert("请输入联系人姓名");
                                        return;
                                    }
                                    if ($("#lxrsj").val() == "") {
                                        //$.tips({
                                        //    content: "请输入联系人手机",
                                        //    stayTime: 2000,
                                        //    type: "warn"
                                        //})
                                        alert("请输入联系人手机");
                                        return;
                                    }
                                    else {
                                        var reg = /^(?:13\d|14\d|15\d|17\d|18\d)-?\d{5}(\d{3}|\*{3})$/;
                                        if (!reg.test($("#lxrsj").val())) {
                                            //$.tips({
                                            //    content: "联系人手机格式错误",
                                            //    stayTime: 2000,
                                            //    type: "warn"
                                            //})
                                            alert("联系人手机格式错误");
                                            return;
                                        }
                                    }
                                    if ($("#bmrs").val() == "") {
                                        //$.tips({
                                        //    content: "请输入报名人数",
                                        //    stayTime: 2000,
                                        //    type: "warn"
                                        //})
                                        alert("请输入报名人数");
                                        return;
                                    }
                                    else {
                                        var reg = /^\+?[1-9][0-9]*$/;
                                        if (!reg.test($("#bmrs").val())) {
                                            //$.tips({
                                            //    content: "报名人数输入错误",
                                            //    stayTime: 2000,
                                            //    type: "warn"
                                            //})
                                            alert("报名人数输入错误");
                                            return;
                                        }
                                        else {
                                            if (parseInt($("#bmrs").val()) > 100) {
                                                //$.tips({
                                                //    content: "报名人数必须小于100",
                                                //    stayTime: 2000,
                                                //    type: "warn"
                                                //})
                                                alert("报名人数必须小于100");
                                                return;
                                            }
                                        }
                                    }

                                    model.bmData.BMCount = $("#bmrs").val();
                                    model.bmData.BMLxDH = $("#lxrsj").val();
                                    model.bmData.BMLxr = $("#lxr").val();

                                    var lg = $.loading({
                                        content: '保存中...',
                                    })

                                    $.getJSON('/API/WXAPI.ashx?Action=ADDHDBMITEM&r=' + Math.random(), { P1: JSON.stringify(model.bmData.$model) }, function (resultData) {
                                        lg.hide();
                                        if (resultData.ErrorMsg == "") {
                                            scel.BMLxr = model.bmData.BMLxr;
                                            scel.BMLxDH = model.bmData.BMLxDH;
                                            scel.BMCount = model.bmData.BMCount;
                                            layer.close(tc);
                                            $("#bmcj").hide();
                                            var el = $.tips({
                                                content: "保存成功",
                                                stayTime: 2000,
                                                type: "success"
                                            })
                                            el.on("tips:hide", function () {
                                                //window.location.reload();
                                            })
                                        }
                                        else {
                                            //$.tips({
                                            //    content: "保存失败，原因：" + resultData.ErrorMsg,
                                            //    stayTime: 2000,
                                            //    type: "warn"
                                            //})
                                            alert("保存失败，原因：" + resultData.ErrorMsg);
                                        }

                                    })
                                }, no: function () {
                                }
                            })
                        }
                    })
                    
                }

            });

            function issc(str1,str2) {

                if (str1 == model.nowuser && !MobileCom.compareDate(str2.substring(0, 10), "")) {
                    //return '<div class="ui-badge-corner" style="position: relative;background-color:green;margin-right:20px; " ms-click="bj(el)">修改</div><div class="ui-badge-corner" style=" position: relative; " ms-click="sc(el)">删除</div>';
                    return '<p class="v" style="margin-top:0"><a href="#" ms-click="sc(el)" style="float:right;"><img src="../Images/delete.png" style="width:20px;height:20px" /><span style="color:black">删除</span></a><a href="#" ms-click="bj(el)" style="float:right;margin-right:10px"><img src="../Images/edit.png" style="width:20px;height:20px" /><span style="color:black">编辑</span></a><div style="clear: both"></div></p>'
                }
                else {
                    return '';
                }

            }


            //$(window).scroll(function () {

            //    if ($(document).height() - $(this).scrollTop() - $(this).height() < 40) {
            //        loadMore();
            //    }

            //})

            function hd() {
                var lg = $.loading({
                    content: '加载中...',
                })
                $.getJSON("/API/WXAPI.ashx?Action=GETHDBMMODEL&r=" + Math.random(), { P1: strId }, function (rt) {
                    
                    if (rt.ErrorMsg == "") {
                        model.hdtime = rt.Result.HDTime;

                        //var isjz = window.localStorage.getItem("isjz");
                        //if (isjz == 0) {
                        //    window.localStorage.setItem("isjz", 1);
                        //    var page = window.localStorage.getItem("page1");
                        $.getJSON("/API/WXAPI.ashx?Action=GETHDBMITEM&r=" + Math.random(), { P1: strId }, function (r) {
                            lg.hide();
                            if (r.ErrorMsg == "") {
                                model.ctData.pushArray(r.Result);
                                //if (r.Result.length > 0) {
                                //    model.ctData.pushArray(r.Result);
                                //    if (r.Result.length < 8) {
                                //        window.localStorage.setItem("page1", 0);
                                //        $("#hdpullDown").find(".pullDownLabel").text("已加载所有数据");
                                //        $("#hdpullDown").removeClass("loading");
                                //        $("#hdpullDown span").eq(0).hide();

                                //    }
                                //    else {
                                //        var page = window.localStorage.getItem("page1");
                                //        window.localStorage.setItem("page1", parseInt(page) + 1);
                                //    }
                                //} else {
                                //    var page = window.localStorage.getItem("page1");
                                //    if (page == "1") {
                                //        $("#hdpullDown").find(".pullDownLabel").text("没有数据");
                                //        $("#hdpullDown").removeClass("loading");
                                //        $("#hdpullDown span").eq(0).hide();
                                //    }
                                //    else {
                                //        window.localStorage.setItem("page1", 0);
                                //        $("#hdpullDown").find(".pullDownLabel").text("已加载所有数据");
                                //        $("#hdpullDown").removeClass("loading");
                                //        $("#hdpullDown span").eq(0).hide();
                                //    }
                                //}



                            } else {

                            }
                            //        window.localStorage.setItem("isjz", 0);
                        })
                        //}
                    }
                })
                
            }

            //function loadMore() {
            //    var page = window.localStorage.getItem("page1");
            //    if (page != "0") {
            //        hd();
            //    }
            //}
            avalon.ready(function () {
                
                $.post("/API/SZHLAPI.ashx?Action=GetUserInfo&r=" + Math.random(), {}, function (data) {

                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        model.nowuser = data.Result.User.UserName;
                        hd();
                    }
                });
            })

            function back() {
                window.location.replace("UI_HDBM_INFO.html?ID=" + strId + "&r=" + Math.random());
            }
        </script>
</body>
</html>
